package com.heima.tess4j;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;

import java.io.File;

public class Application {
    public static void main(String[] args) {
        try{
            //获取本地图片
            File file=new File("D:\\img\\images.png");
            //创建tess对象
            ITesseract tesseract=new Tesseract();
            //设置字体库路径
            tesseract.setDatapath("E:\\develop\\tessdata");
            //中文识别
            tesseract.setLanguage("chi_sim");
            //执行OCR识别
            String result = tesseract.doOCR(file);
            //替换回车和tab键
            result=result.replaceAll("\\r|\\n","-").replaceAll(" ","");
            System.out.println("结果为："+result);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
